﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;

namespace sy2_11
{
    public partial class Form1 : Form
    {
        private List<int> num = new List<int>();
        private List<int> prime = new List<int>();
        private Random random = new Random();

        public Form1()
        {
            InitializeComponent();
        }
        private bool IsPrime(int number)
        {
            if (number <= 1) return false;
            if (number == 2) return true;
            if (number % 2 == 0) return false;
            for (int i = 3; i * i <= number; i += 2)
            {
                if (number % i == 0)
                    return false;
            }
            return true;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            num.Clear();
            prime.Clear();
            textBox4.Clear();
            textBox5.Clear();

            int count = int.Parse(textBox1.Text);
            int min = int.Parse(textBox2.Text);
            int max = int.Parse(textBox3.Text);

            for (int i = 0; i < count; i++)
            {
                int randomNumber = random.Next(min, max + 1);
                num.Add(randomNumber);

                if (IsPrime(randomNumber))
                {
                    prime.Add(randomNumber);
                }
            }

            textBox4.Text = string.Join(Environment.NewLine, num);

            textBox5.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox5.Text = string.Join(Environment.NewLine, prime);
        
        }
    }
}
